﻿
                                  <div class="box border primary">
											<div class="box-title">
												<h4><i class="fa fa-bars"></i>Form controls</h4>
												<div class="tools hidden-xs">
													<a href="#box-config" data-toggle="modal" class="config">
														<i class="fa fa-cog"></i>
													</a>
													<a href="javascript:;" class="reload">
														<i class="fa fa-refresh"></i>
													</a>
													<a href="javascript:;" class="collapse">
														<i class="fa fa-chevron-up"></i>
													</a>
													<a href="javascript:;" class="remove">
														<i class="fa fa-times"></i>
													</a>
												</div>
											</div>
											<div class="box-body big">
												<h3 class="form-title">管理员添加</h3>
												<form method="post" action="" class="form-horizontal" role="form" enctype="multipart/form-data">
												  <div class="form-group">
													<label class="col-sm-3 control-label">名字</label>
													<div style="width:auto;float:left" class="col-sm-10 pid">
															<input name="username" class="form-control" placeholder="支持字母、数字，4-20个字符" type="text">

													</div>
													<span></span>
												  </div>


												  <div class="form-group">
													<label class="col-sm-3 control-label">密码</label>
													<div style="width:auto;float:left" class="col-sm-1 pid">
															<input name="password" class="form-control" placeholder="请输入密码" type="password">
													</div>
													<span></span>
												  </div>

												  <div class="form-group">
													<label class="col-sm-3 control-label">邮箱</label>
													<div style="width:auto;float:left" class="col-sm-1 pid">
															<input name="email" class="form-control" placeholder="" type="text">
													</div>
													<span></span>
												  </div>


												  <div class="form-group">
													<label class="col-sm-3 control-label">所属角色组</label>
													<div style="width:auto;float:left" class="col-sm-1 pid">
															<select name="name" class="form-control">
															<?php foreach($date as $k=>$v): ?>
															<option><?php echo $v['name']?></option>
														    <?php endforeach;?>
															</select>
													</div>
												  </div>	  
                                                <div class="col-sm-offset-3 col-sm-13">
                                                 <button  type="submit" class="btn btn-success">提交</button>
													</div>
												 </form>
											</div>
										</div>
<script src="public/admin/js/jquery/jquery-2.0.3.min.js"></script>

<script type="text/javascript">
$(function(){
		$('input[name=username]').blur(function(){
			var val=$(this).val();
			var obj=$(this);
			var reg=/^[a-z][a-z0-9_]{3,20}/;
			if(reg.test(val)){
				$(this).parent().siblings('span').html('<font color="green">正确</font>');
						$.ajax({
						type:'get',
						dataType:'json',
						url:'index.php?c=admin&a=add&username='+val,
						success:function(res){
						if(res!=''){
						obj.parent().siblings('span').html('<font color="red">该管理员已经被注册</font>');

						return false;
						obj.focus();

						}else{
						obj.parent().siblings('span').html('<font color="green">恭喜你，用户名可以使用！</font>');

						}

						}
						});				
			}else{
			$(this).parent().siblings('span').html('<font color="red">用户名有误</font>');

			$(this).focus();
			
			 return false;
			}
			
		});

	    $('input[name=password]').blur(function(){
	  	var val=$(this).val();
	  	var reg=/\w{6,20}/;
	  	if(reg.test(val)){
	       $(this).parent().siblings('span').html('<font color="green">密码正确</font>');

	  	}else{
	  		$(this).parent().siblings('span').html('<font color="red">密码有误</font>');
	  		$(this).focus();

	  		 return false;
	  	}
	  
	  });






	    $('input[name=email]').blur(function(){
	  	var val=$(this).val();
	  	var reg=/\w+[@]{1}\w+\.(com|cn)$/;
	  	if(reg.test(val)){
	       $(this).parent().siblings('span').html('<font color="green">邮箱格式正确</font>');

	  	}else{
	  		$(this).parent().siblings('span').html('<font color="red">邮箱格式有误</font>');
	  		$(this).focus();
	  		 return false;
	  	}
	  
	  });
})
</script>
